<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.isomorphic.rpc.*" %>
<%@ page import="com.isomorphic.datasource.*" %>
<%@ page import="com.isomorphic.sql.*" %>
<%@ page import="com.isomorphic.log.*" %>
<%@ page import="com.isomorphic.util.*" %>

<%
DataSource userDS;
DataSource depDS;

//获得datasource
try {
    userDS = DataSourceManager.getDataSource("user");
    depDS = DataSourceManager.getDataSource("depDS");
} catch (Exception e) {
    throw new Exception("Could not load user or company ds");
}
//获得用户
Map c = new HashMap();
c.put("telephone",request.getParameter("username"));
c.put("password",request.getParameter("password"));
c.put("smStatus","true");
Map user = userDS.fetchSingle(c);
if(user == null){
	out.println("用户名或密码不正确");
	return;
}
session.setAttribute("currUser",user);

//设置角色
if(user.get("admin") != null && user.get("admin").toString().equals("true")){
	if(user.get("dep_pk").equals(user.get("corp_sid"))){
		//如果是所属部门为公司，为公司管理员
		session.setAttribute("roles","comAdmin");
	}else{
		//部门管理员
		session.setAttribute("roles","depAdmin");
	}
}else{
	session.setAttribute("roles","user");
}

//登录成功，转向主页面
response.sendRedirect("index.jsp");

%>